package com.hanhanxiaochong.zhongxiangchuanmei.presenter.base;

import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseApi;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.IBaseView;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by Administrator on 2017/1/4/0004.
 */

public abstract class BasePresenter<T extends IBaseView>{

    protected T iView;
    protected int mState=0;
    protected final HttpPostService api;
    private final CompositeSubscription mCompositeSubscription = new CompositeSubscription();

    public BasePresenter(T iView) {
        this.iView = iView;
        api = RetrofitSource.createApi(HttpPostService.class);
    }


    public void unsubscribeTasks() {
        mCompositeSubscription.unsubscribe();
    }

    /**
     * 每次发起时加入CompositeSubscription,这个方法应该内部调用，所以使用protected.
     */
    protected void addSubscription(Subscription subscription) {
        mCompositeSubscription.add(subscription);
    }

    /**
     * http请求
     * @param rxAppCompatActivity
     * @param baseApi
     */
    public abstract void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi);

    /**
     * http请求
     * @param rxAppCompatActivity
     * @param baseApi
     * @param state
     */
    public abstract void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi, int state);

}
